package guda.demox.biz.impl;

import guda.demox.biz.BlogBiz;
import guda.demox.biz.common.BizResult;
import guda.demox.biz.form.BlogEditForm;
import guda.demox.biz.form.BlogForm;
import guda.demox.dal.common.PageQuery;
import guda.demox.dal.model.BlogDO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * Created by well on 2017/11/8.
 */
@Service
public class BlogBizImpl implements BlogBiz {

    private final Logger logger = LoggerFactory.getLogger(getClass());

//    @Autowired
//    private BlogDAO blogDAO;

    @Override
    public BizResult detail(long id) {
        BizResult bizResult = new BizResult();
//        try{
//            BlogDO blogDO = blogDAO.selectById(id);
//            bizResult.data.put("blogDO", blogDO);
//            bizResult.success = true;
//        }catch(Exception e){
//            logger.error("query blog error",e);
//        }
        return bizResult;
    }

    @Override
    public BizResult list(PageQuery pageQuery) {
        BizResult bizResult = new BizResult();
        try {
//            int totalCount = blogDAO.countForPage(pageQuery);
//            pageQuery.setTotalCount(totalCount);
//            List<BlogDO> blogList = blogDAO.selectForPage(pageQuery);
//            bizResult.data.put("blogList", blogList);
//            bizResult.data.put("query", pageQuery);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("view blog list error", e);
        }
        return bizResult;
    }

    @Override
    public BizResult delete(long id) {
        BizResult bizResult = new BizResult();
        try {
          //  blogDAO.delById(id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("delete blog error", e);
        }
        return bizResult;
    }

    @Override
    public BizResult create(BlogForm blogForm) {
        BizResult bizResult = new BizResult();
        try {
            BlogDO blogDO = blogForm.toDO();
            //long id = blogDAO.insert(blogDO);
            //bizResult.data.put("id", id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("create blog error", e);
        }
        return bizResult;
    }

    @Override
    public BizResult update(BlogEditForm blogEditForm) {
        BizResult bizResult = new BizResult();
        try {
            BlogDO blogDO = blogEditForm.toDO();
            //blogDAO.updateByIdSelective(blogDO);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("update blog error", e);
        }
        return bizResult;
    }
}
